package com.ruoyi.project.question.grade.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.question.grade.domain.QuestionnarieGrade;
import com.ruoyi.project.question.grade.service.IQuestionnarieGradeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * gradeController
 * 
 * @author Bandit
 * @date 2021-12-14
 */
@Controller
@RequestMapping("/question/grade")
public class QuestionnarieGradeController extends BaseController
{
    private String prefix = "question/grade";

    @Autowired
    private IQuestionnarieGradeService questionnarieGradeService;

    @RequiresPermissions("question:grade:view")
    @GetMapping()
    public String grade()
    {
        return prefix + "/grade";
    }

    /**
     * 查询grade列表
     */
    @RequiresPermissions("question:grade:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QuestionnarieGrade questionnarieGrade)
    {
        startPage();
        List<QuestionnarieGrade> list = questionnarieGradeService.selectQuestionnarieGradeList(questionnarieGrade);
        return getDataTable(list);
    }

    /**
     * 导出grade列表
     */
    @RequiresPermissions("question:grade:export")
    @Log(title = "grade", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QuestionnarieGrade questionnarieGrade)
    {
        List<QuestionnarieGrade> list = questionnarieGradeService.selectQuestionnarieGradeList(questionnarieGrade);
        ExcelUtil<QuestionnarieGrade> util = new ExcelUtil<QuestionnarieGrade>(QuestionnarieGrade.class);
        return util.exportExcel(list, "grade数据");
    }

    /**
     * 新增grade
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存grade
     */
    @RequiresPermissions("question:grade:add")
    @Log(title = "grade", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QuestionnarieGrade questionnarieGrade)
    {
        return toAjax(questionnarieGradeService.insertQuestionnarieGrade(questionnarieGrade));
    }

    /**
     * 修改grade
     */
    @RequiresPermissions("question:grade:edit")
    @GetMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
    {
        QuestionnarieGrade questionnarieGrade = questionnarieGradeService.selectQuestionnarieGradeByUserId(userId);
        mmap.put("questionnarieGrade", questionnarieGrade);
        return prefix + "/edit";
    }

    /**
     * 修改保存grade
     */
    @RequiresPermissions("question:grade:edit")
    @Log(title = "grade", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QuestionnarieGrade questionnarieGrade)
    {
        return toAjax(questionnarieGradeService.updateQuestionnarieGrade(questionnarieGrade));
    }

    /**
     * 删除grade
     */
    @RequiresPermissions("question:grade:remove")
    @Log(title = "grade", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(questionnarieGradeService.deleteQuestionnarieGradeByUserIds(ids));
    }
}
